package com.project.internship.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.internship.entity.Teacher;
import com.project.internship.mapper.TeacherMapper;
import com.project.internship.service.TeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.internship.utils.UserUtils;
import com.project.internship.utils.YearUtils;
import com.project.internship.vo.TeacherDeptVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2020-04-07
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

    @Autowired
    TeacherMapper teacherMapper;

    /**
     * 学院端查询教师信息
     * @param page
     * @param keyword 工号
     * @return
     */
    @Override
    public IPage<Teacher> getAllTeachers(Page<Teacher> page, String keyword) {
        return teacherMapper.getAllTeachers(page, UserUtils.getCurrentUser().getDepartmentId(), keyword);
    }

    @Override
    public Integer addTeacher(Teacher teacher) {
        Integer id = UserUtils.getCurrentUser().getDepartmentId();
        teacher.setDepartmentId(id);
        return teacherMapper.insert(teacher);
    }

    @Override
    public Integer updateTeacher(Teacher teacher) {
        return teacherMapper.updateById(teacher);
    }

    @Override
    public Integer deleteTeacher(Long id) {
        return teacherMapper.deleteById(id);
    }

    @Override
    public Integer deleteTeachers(Long[] ids) {
        return teacherMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 学院端实习分配
     * 获得所有教师信息
      * @return
     */
    @Override
    public List<Teacher> getNonTeacherName() {
        return teacherMapper.getNonTeacherName(UserUtils.getCurrentUser().getDepartmentId(), YearUtils.getCurrentYear());
    }

    @Override
    public List<Teacher> getBaseTeacher(Integer bid) {
        return teacherMapper.getBaseTeacher(bid, UserUtils.getCurrentUser().getDepartmentId(), YearUtils.getCurrentYear());
    }

    @Override
    public List<TeacherDeptVO> getTeacherSelfInfo() {
        return teacherMapper.getTeacherSelfInfo(UserUtils.getCurrentUser().getTeacherId());
    }

    @Override
    public Integer updateTeacherSelfInfo(TeacherDeptVO teacherDeptVO) {
        Teacher teacher = new Teacher();
        teacher.setId(teacherDeptVO.getId());
        teacher.setName(teacherDeptVO.getTname());
        teacher.setJobTitle(teacherDeptVO.getJobTitle());
        teacher.setTelephone(teacherDeptVO.getTelephone());
        teacher.setEmail(teacherDeptVO.getEmail());
        teacher.setGender(teacherDeptVO.getGender());

        return teacherMapper.updateById(teacher);
    }


}
